package com.shan.mybatis.controllor;

import com.shan.mybatis.anno.Log;
import com.shan.mybatis.pojo.Dept;
import com.shan.mybatis.pojo.Result;
import com.shan.mybatis.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
@Slf4j
@RestController
public class DepControllor {
    @Autowired
    private DeptService service;

    @GetMapping("/depts")
    public Result list() {
        log.info("查询全部部门信息");
        List<Dept> list = service.list();
        return Result.success(list);
    }
@Log
    @DeleteMapping("/depts/{id}")
    public Result deleteByid(@PathVariable Integer id) {
        log.info("根据id删除部门");
        service.deleteById(id);
        return Result.success();
    }
    @Log
    @PostMapping("/depts")
    public Result addDept(@RequestBody Dept dept) {
        service.addDept(dept);
        return Result.success();
    }

    @GetMapping("/depts/{id}")
    public Result selectById(@PathVariable Integer id) {
       Dept dept = service.selectByid(id);
        return Result.success(dept);
    }
    @Log
    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept) {
        service.update(dept);
        return Result.success();
    }
}
